package graphic;

import java.awt.Color;
import java.awt.Graphics;

import model.Particle;

public class ParticlePainter extends Painter{
	
	public ParticlePainter(Particle particle){
		super(particle);
	}
	
	private Color render(Particle p){
		if(p.getLife()==0){
			return color;
		}else{
			int r = color.getRed();
			int g = color.getGreen();
			int b = color.getBlue();
			double fuctor = p.getAge()*1.0/p.getLife();
			
			int newR = r+(int)((255-r)*fuctor);
			int newG = g+(int)((255-g)*fuctor);
			int newB = b+(int)((255-b)*fuctor);
			Color color = new Color(newR,newG,newB);
			return color;
		}
	}
	
	public void paint(Graphics graphic){
		Color render = render(particle);
		
		graphic.setColor(render);
		graphic.fillOval((int)particle.getPosition().getX(), (int)particle.getPosition().getY(), particle.getRadius()*2, particle.getRadius()*2);
	}
}
